# coding: utf-8
from sqlalchemy import Column, DateTime, Integer, String
from sqlalchemy.schema import FetchedValue
from flask_sqlalchemy import SQLAlchemy
from application import db


class User(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    nickname = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    company = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    login_name = db.Column(db.String(20, 'utf8mb4_0900_ai_ci'), unique=True)
    login_pwd = db.Column(db.String(32, 'utf8mb4_0900_ai_ci'))
    login_salt = db.Column(db.String(32, 'utf8mb4_0900_ai_ci'))
    status = db.Column(db.Integer, server_default=db.FetchedValue(), info='1pass')
    role = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'))
    updated_time = db.Column(db.DateTime)
    created_time = db.Column(db.DateTime)

    # work_list = db.relationship('WorkList', backref='user')
    # # work_list = db.relationship('WorkList', primaryjoin="or_(User.id==WorkList.createuid, User.id==WorkList.uid)",
    # #                           lazy='dynamic')
    # # repr()方法显示一个可读字符串
    def __repr__(self):
        return '%s' % self.nickname
